package com.bjpowernode.controller;

import com.bjpowernode.entity.TClueRemark;
import com.bjpowernode.entity.TCustomerRemark;
import com.bjpowernode.query.ClueRemarkQuery;
import com.bjpowernode.query.CustomerRemarkQuery;
import com.bjpowernode.result.R;
import com.bjpowernode.service.CustomerRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class CustomerRemarkController {

    @Resource
    private CustomerRemarkService customerRemarkService;

    /**
     * 提交客户跟踪记录
     *
     * @param customerRemarkQuery
     * @return
     */
    @PostMapping(value = "/api/customer/remark")
    public R addCustomerRemark(@RequestBody CustomerRemarkQuery customerRemarkQuery) {
        int save = customerRemarkService.saveCustomerRemark(customerRemarkQuery);
        return save >= 1 ? R.OK() : R.FAIL();
    }

    @GetMapping(value = "/api/customer/remarks")
    public R cluePage(@RequestParam(value = "current", required = false) Integer current,
                      @RequestParam(value = "customerId") Integer customerId) {
        // required = false 表示current参数可以传，也可以不传，也就是current参数可以是空的；
        // required = true 表示current参数必须传，不传会报错；
        if (current == null) {
            current = 1;
        }
        PageInfo<TCustomerRemark> pageInfo = customerRemarkService.getCustomerRemarkPage(current, customerId);
        return R.OK(pageInfo);
    }
}
